<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
  <th:block th:include="include :: header('新增尺码')"/>
  <th:block th:include="include :: select2-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
  <form class="form-horizontal m" id="form-size-add">
    <div class="form-group">
      <label class="col-sm-3 control-label is-required">尺码编码：</label>
      <div class="col-sm-8">
        <input name="sizeCode" class="form-control" type="text" required>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label">尺码名称：</label>
      <div class="col-sm-8">
        <input name="sizeName" class="form-control" type="text">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label">尺码组：</label>
      <div class="col-sm-8">
        <select id="sizeGroup" class="form-control select2-multiple">
          <option th:each="sizeGroup:${sizeGroups}" th:value="${sizeGroup.sizeGroupId}" th:text="${sizeGroup.sizeGroupName}"
                  th:disabled="${sizeGroup.status == '1'}"></option>
        </select>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label">显示顺序：</label>
      <div class="col-sm-8">
        <input name="orderNum" class="form-control" type="text">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label">状态：</label>
      <div class="col-sm-8">
        <div class="radio-box" th:each="dict : ${@dict.getType('pro_size_status')}">
          <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
          <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
        </div>
      </div>
    </div>
  </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script type="text/javascript">
  var prefix = ctx + "product/size"
  $("#form-size-add").validate({
    focusCleanup: true
  });

  function submitHandler() {
    if ($.validate.form()) {
      let formdata = new FormData();
      formdata.append("sizeCode", $("input[name='sizeCode']").val());
      formdata.append("sizeName", $("input[name='sizeName']").val());
      formdata.append("orderNum", $("input[name='orderNum']").val());
      formdata.append("status", $("input[name='status']:checked").val());
      formdata.append("sizeGroupId", $.form.selectSelects("sizeGroup"));

      $.ajax({
        url: prefix + "/add",
        type: "post",
        data: formdata,
        processData: false,
        contentType: false,
        success: function (result) {
          $.operate.saveSuccess(result);
        }
      })
    }
  }
</script>
</body>
</html>